package hwr.iamdr.Service;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import javax.servlet.http.HttpServletResponse;

public class SetCharSet implements javax.servlet.Filter
{
	static final Logger logger	= Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);

	@Override
	public void doFilter(ServletRequest req,ServletResponse resp,FilterChain chain) throws IOException,ServletException
	{
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		if(resp instanceof HttpServletResponse)
		{
			HttpServletResponse httpResp	= (HttpServletResponse)resp;
			httpResp.setHeader("Cache-Control","no-cache");
			httpResp.setHeader("Pragma", "No-cache");
			httpResp.setDateHeader("Expires",1);
		}
		else logger.log(Level.SEVERE,"Why we get none HTTP request?");
		chain.doFilter(req,resp);
	}

	@Override
	public void destroy()
	{
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException
	{
	}
}
